import java.io.*; class demo { public static void main(String args[])throws Exception { int arr[]={134654665,284976359,375696944,478499493,588388383, 698876566,764545453,855454545,978656544,107474733}; PrintStream ps=new PrintStream("c:/temp/num.lst"); for(int i=0;i<arr.length;i++) ps.println(arr[i]); ps.close(); System.out.println("Data Stored..."); } }
Data Stored...
import java.io.Serializable; class Student implements Serializable { private int rollno; private String name; public Student(int rn,String nm) { rollno=rn; name=nm; } public void showData() { System.out.println("Rollno is "+rollno); System.out.println("Name is "+name); } }
import java.io.*; class demo { public static void main(String args[])throws Exception { Student a=new Student(4117,"Amit jain"); Student b=new Student(3012,"Gopal pandey"); Student c=new Student(5126,"Mona Mantri"); FileOutputStream fout=new FileOutputStream("c:/temp/stud.lst"); ObjectOutputStream os=new ObjectOutputStream(fout); os.writeObject(a); os.writeObject(b); os.writeObject(c); os.close(); fout.close(); System.out.println("objects saved...."); } }
Data Stored...
import java.io.*; class demo { public static void main(String args[])throws Exception { FileInputStream fin=new FileInputStream("c:/temp/stud.lst"); ObjectInputStream os=new ObjectInputStream(fin); Student x=(Student)os.readObject(); Student y=(Student)os.readObject(); Student z=(Student)os.readObject(); os.close(); fin.close(); x.showData(); y.showData(); z.showData(); } }